In [1]:
drive_path = 'c:/'
import numpy as np
import pandas as pd
import os
import sys
import matplotlib.pyplot as plt
from scipy.stats import ks_2samp
from scipy.stats import anderson_ksamp
from scipy.stats import kruskal
from scipy.stats import variation
from scipy.stats import spearmanr
from scipy.stats import zscore
from scipy.stats import gaussian_kde
import seaborn as sns
%matplotlib


Using matplotlib backend: Qt4Agg

In [4]:
#Import data
comp=pd.read_csv('C:\Users\Annie\Documents\Data\Ca_Imaging\GoodFiles\\fullpeak.csv')
# del comp['Mouse']
comp_sorted=comp.reindex_axis(comp.mean().sort_values().index, axis=1)
comp_labels=pd.DataFrame(comp.Group)
tmp=[comp_labels,comp_sorted]
composite_full=pd.concat(tmp,axis=1)

In [8]:
composite_full


Out[8]:
Group MS01 THA MS10 Blank AP MS05 IAA05 PA IAA01 IAA10 Hexanal10 Hexanone Hexanal01 Hexanal05 EB
0 Control 0.015671 0.067358 0.150474 NaN 0.036738 0.169456 0.034294 0.037389 0.188597 0.099708 0.069948 0.093353 0.062999 0.124211 -0.061840
1 Control -0.034636 0.095266 0.074001 NaN 0.073576 0.139423 0.001814 -0.002271 0.188666 0.041676 0.036447 -0.026087 0.014205 0.101018 0.056893
2 Control -0.044179 0.146676 0.260675 NaN 0.058214 0.095906 0.127803 0.221412 0.477065 0.287615 0.263380 0.022945 0.129928 0.293199 0.153817
3 Control 0.146939 0.094015 0.071141 NaN 0.110235 0.157300 0.104363 0.051386 0.248613 0.034975 0.037260 -0.057530 0.104142 0.198974 0.082859
4 Control 0.268299 0.069755 0.220858 NaN 0.116399 0.233311 0.240154 0.203381 0.393188 0.309290 0.145721 -0.147715 0.315627 0.538062 0.694684
5 Control 0.111727 0.037435 0.057728 NaN 0.120034 0.110242 0.040143 0.090297 0.214756 0.176755 0.034764 0.104064 0.095894 0.132652 0.240378
6 Control 0.182874 0.109239 0.216817 NaN 0.121320 0.174829 0.100998 0.207549 0.327782 0.192142 0.284200 -0.029226 0.154322 0.269635 0.190801
7 Control 0.086948 0.125796 0.318744 NaN 0.178972 0.289871 0.204415 0.159999 0.359708 0.357559 0.304030 0.117728 0.252535 0.366130 0.340678
8 Control 0.106260 0.069655 0.196883 NaN 0.146591 0.208539 0.101463 0.022008 0.318061 0.210739 0.197694 0.094518 0.103346 0.247524 0.146396
9 Control 0.154366 0.135341 0.116278 NaN 0.098437 0.145846 0.074407 0.073498 0.267016 0.108806 0.224634 0.017234 0.182850 0.248789 0.210595
10 Control 0.020829 0.094412 0.184697 NaN 0.161861 0.108406 0.112987 0.060587 0.324114 0.157292 0.097157 0.037405 0.151694 0.275390 -0.055042
11 Control -0.093950 0.054919 0.151068 NaN 0.040984 0.258319 0.027133 0.101406 0.268158 0.142971 0.161855 0.066639 0.069175 0.296796 0.225974
12 Control 0.091192 0.010888 0.166464 NaN 0.155852 0.193757 0.111491 0.106643 0.307008 0.095139 0.136115 -0.074851 0.188763 0.233767 0.146903
13 Control 0.369279 0.304778 0.395261 NaN 0.292124 0.344648 0.416227 0.295231 0.630219 0.481450 0.363344 0.141261 0.489794 0.555317 0.541389
14 Control 0.378874 0.393420 0.446905 NaN 0.302194 0.393967 0.393302 0.402526 0.596139 0.491399 0.404896 0.046463 0.449983 0.474505 0.535703
15 Control 0.080862 0.152374 0.233902 NaN 0.114072 0.123240 0.034678 -0.006049 0.274827 0.146583 0.535881 -0.081978 0.174693 0.353019 0.089853
16 Control 0.117418 0.137338 0.224426 NaN 0.188199 0.191459 0.121752 0.163585 0.377932 0.091512 0.139204 -0.064411 0.203577 0.193309 0.226151
17 Control 0.065225 0.203401 0.257005 NaN 0.156923 0.267752 0.140048 0.083191 0.321585 0.143258 0.272514 0.109543 0.205356 0.289709 0.316028
18 Control 0.108320 0.090252 0.000000 NaN 0.042534 -0.015268 0.055558 0.116349 -0.083624 -0.008817 0.313035 0.082941 0.264648 0.275785 0.065891
19 Control 0.179008 0.250166 -0.083117 NaN -0.033500 -0.024729 0.064085 0.228741 0.120508 0.061257 -0.007216 0.087833 0.186326 0.111039 -0.118377
20 Control 0.116572 0.256492 0.156076 NaN 0.000000 0.054946 0.029715 0.237578 0.091919 0.176854 0.144628 0.325181 0.280109 0.179311 0.124066
21 Control 0.191554 0.292102 0.082809 NaN 0.182495 0.043842 0.210674 0.254059 0.128095 0.144310 0.302282 0.506974 0.370468 0.382306 0.346555
22 Control 0.203699 0.325759 0.138751 NaN 0.129621 0.069325 0.140388 0.273195 0.090902 0.181337 0.273259 0.388645 0.267784 0.323214 0.207472
23 Control 0.073796 0.270991 0.025330 NaN 0.087188 0.025849 0.130373 0.206771 0.067984 0.177870 0.219088 0.352660 0.139257 0.245531 0.084610
24 Control 0.117774 0.259623 0.007929 NaN -0.034014 -0.051472 0.047946 0.204714 0.008028 0.036658 0.137578 0.211784 0.238933 0.179419 0.147815
25 Control 0.146185 0.314496 0.128533 NaN 0.147234 0.067943 0.262951 0.274714 0.099278 0.188441 0.309170 0.487385 0.320584 0.349342 0.199915
26 Control 0.114494 0.215612 -0.009991 NaN -0.049796 -0.075608 -0.135574 0.175379 0.061119 0.123982 0.073634 0.306677 0.127770 0.188801 0.046998
27 Control 0.215789 0.347873 0.081824 NaN 0.185270 0.061863 0.209565 0.241287 -0.033961 0.231254 0.336785 0.350017 0.382028 0.380090 0.234191
28 Control 0.188919 0.392648 0.140227 NaN 0.255000 0.176849 0.299058 0.303361 0.179978 0.244171 0.408181 0.576689 0.423290 0.450193 0.424744
29 Control 0.157538 0.307059 0.035912 NaN 0.076950 0.043795 0.200615 0.294997 0.145997 0.166541 0.307000 0.410130 0.340449 0.388505 0.282116
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
834 Hexanal 0.181104 0.159880 0.095290 0.176696 0.152788 0.086454 0.120283 0.173220 0.159671 0.245698 0.196824 0.188371 0.293106 0.245436 0.322258
835 Hexanal 0.389073 0.324472 0.248939 0.303931 0.318245 0.353815 0.408329 0.313855 0.508018 0.878715 0.510822 0.671744 0.676706 0.578821 0.910795
836 Hexanal 0.544788 0.411234 0.393640 0.412845 0.430457 0.429287 0.509418 0.412677 0.624770 1.199948 0.664191 0.801545 0.873037 0.793721 1.243407
837 Hexanal 0.447415 0.346698 0.297007 0.328434 0.346832 0.348963 0.389336 0.347241 0.501567 0.852661 0.515395 0.632668 0.691432 0.591818 1.029620
838 Hexanal 0.793257 0.840489 0.780886 1.095223 1.090293 1.078821 1.292346 1.546832 1.022429 1.174090 1.555245 1.422125 2.266583 2.034561 2.129344
839 Hexanal 0.595034 0.658295 0.618527 0.797135 0.832029 0.761413 0.818725 1.216535 0.781367 0.995138 0.909814 1.018964 1.506151 1.261135 2.526371
840 Hexanal 0.966486 0.989802 0.836932 1.384991 1.365151 1.272079 1.548634 1.917040 1.505599 1.418888 1.640441 1.516164 2.563843 2.303096 2.787493
841 Hexanal 0.546975 0.640469 0.504446 0.719937 0.762032 0.708351 0.749359 1.263250 0.739663 0.874148 0.986786 1.102305 1.676727 1.565281 2.872082
842 Hexanal 0.658356 0.711120 0.588638 0.841005 0.879471 0.719807 0.908630 1.419908 0.934317 1.005188 1.101359 1.148194 1.734501 1.591737 2.623944
843 Hexanal 0.630018 0.754369 0.595570 0.822605 0.900622 0.830883 0.866808 1.396514 0.913956 1.050029 1.183918 1.311492 1.869054 1.748430 3.141432
844 Hexanal 1.082640 1.094984 0.964603 1.381271 1.527919 1.422797 1.575182 2.046118 1.526247 1.504693 1.542618 1.586757 2.357052 2.172976 3.826471
845 Hexanal 1.013227 0.862930 0.849189 1.445143 1.407350 1.258272 1.684370 2.186634 1.402611 1.391010 1.770982 1.607878 2.772549 2.581480 3.415339
846 Hexanal 1.152971 1.247013 1.200526 1.798361 1.404953 1.417057 1.672553 2.580121 1.609253 1.746266 1.401101 1.584898 1.717721 1.801754 4.020523
847 Hexanal 0.699582 0.843323 0.665351 0.962635 1.039162 0.936519 1.004865 1.619284 1.113527 1.207161 1.322811 1.432008 2.195427 1.924846 3.575100
848 Hexanal 0.716213 0.788115 0.774952 1.354953 0.991606 0.925677 1.016880 1.552607 1.222315 1.246317 1.339570 1.394285 1.905985 1.775453 3.256687
849 Hexanal 0.531458 0.653229 0.517799 0.602377 0.807217 0.654638 0.725877 1.243463 0.731349 0.867002 0.886901 0.868230 1.638102 1.354528 2.497531
850 Hexanal 0.572785 0.629955 0.528996 0.750101 0.824932 0.724944 0.801074 1.431916 0.848512 0.965630 1.110041 1.118559 1.910358 1.726280 3.091349
851 Hexanal 0.572612 0.691922 0.579909 0.826706 0.850738 0.782729 0.851013 1.247947 0.875808 0.978271 1.100468 1.123620 1.645770 1.582939 2.897091
852 Hexanal 0.672445 0.763993 0.610116 0.888589 0.926281 0.830295 0.885531 1.405602 0.950825 1.056649 1.116324 1.115635 1.868433 1.651447 3.002847
853 Hexanal 0.538502 0.560071 0.581656 0.988494 0.823965 0.779066 1.087038 1.132195 0.855367 0.886160 1.249677 1.063934 1.972469 1.908076 1.644408
854 Hexanal 0.438665 0.498920 0.452694 0.660369 0.706064 0.626519 0.756525 1.007751 0.690541 0.724751 0.928549 0.837125 1.664893 1.469356 2.301010
855 Hexanal 0.599032 0.748503 0.587267 0.845729 0.901124 0.818445 0.930967 1.663550 0.955184 1.032107 1.249846 1.278412 2.197273 1.934651 3.717106
856 Hexanal 1.051300 1.010457 0.979908 1.336478 1.392174 1.250843 1.420872 1.777093 1.349172 1.435614 1.423792 1.599798 2.181211 2.062611 3.135329
857 Hexanal 0.937357 1.046055 0.901857 1.411247 1.356020 1.291265 1.546961 1.823566 1.334017 1.371565 1.558815 1.736236 2.160846 2.285698 2.555852
858 Hexanal 0.667952 0.668923 0.676167 1.069231 1.010240 0.928498 1.150083 1.336684 0.975513 1.052993 1.434971 1.226314 2.351320 2.098948 2.778626
859 Hexanal 1.031158 1.143285 0.989754 1.587848 1.541542 1.436682 1.766625 2.254194 1.592493 1.693706 1.865025 1.920752 2.819429 2.629784 3.687546
860 Hexanal 1.400407 1.366231 1.175714 1.998268 1.728571 1.623015 2.125974 2.662913 1.775568 1.779149 1.564008 1.880092 2.218953 2.228448 4.049244
861 Hexanal 1.214286 1.232045 1.112228 1.604857 1.699394 1.531750 1.807049 2.502156 1.688099 1.928131 1.801421 1.978840 2.581810 2.581529 4.306552
862 Hexanal 1.126687 1.142736 1.016472 1.439867 1.443458 1.344620 1.589192 2.310852 1.427219 1.555190 1.326305 1.615310 1.997744 1.906673 3.434703
863 Hexanal 1.153281 1.291196 1.075004 1.624926 1.597203 1.557423 1.765533 2.306579 1.648026 1.751610 1.611298 2.007368 2.274752 2.273161 3.634535

864 rows × 16 columns


In [9]:
#Calculate means and variance for each odor
Cctrl=composite_full[composite_full['Group']=='Control']
Cmean=pd.DataFrame(Cctrl.mean())
Cmean.columns=['Control Mean']
Cvar=pd.DataFrame(Cctrl.var())
Cvar.columns=['Control Variance']
M=composite_full[composite_full['Group']=='Mint']
Mmean=pd.DataFrame(M.mean())
Mmean.columns=['Mint Mean']
Mvar=pd.DataFrame(M.var())
Mvar.columns=['Mint Variance']
H=composite_full[composite_full['Group']=='Hexanal']
Hmean=pd.DataFrame(H.mean())
Hmean.columns=['Hexanal Mean']
Hvar=pd.DataFrame(H.var())
Hvar.columns=['Hexanal Variance']

#Concat
Ctmp=[Cmean,Cvar]
Mtmp=[Mmean,Mvar]
Htmp=[Hmean,Hvar]

CtrlDF=pd.concat(Ctmp,axis=1)
MDF=pd.concat(Mtmp,axis=1)
HDF=pd.concat(Htmp,axis=1)
final=[CtrlDF,MDF,HDF]
finaldf=pd.concat(final,axis=1)

In [10]:
finaldf=finaldf.reset_index(drop=True)

In [11]:
finaldf.head()


Out[11]:
Control Mean Control Variance Mint Mean Mint Variance Hexanal Mean Hexanal Variance
0 0.134068 0.016237 0.214228 0.046046 0.334160 0.131850
1 0.121986 0.015955 0.287630 0.066521 0.321402 0.076489
2 0.120913 0.021565 0.259338 0.064694 0.388981 0.180210
3 0.068559 0.014854 0.201166 0.006378 0.395827 0.211650
4 0.114220 0.014832 0.240726 0.051352 0.436641 0.191023

In [17]:
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(35, 20));
sns.regplot(finaldf['Control Mean'],finaldf['Control Variance'],scatter_kws={"s": 175},color='r')
sns.regplot(finaldf['Mint Mean'],finaldf['Mint Variance'],scatter_kws={"s": 175},color='g')
sns.regplot(finaldf['Hexanal Mean'],finaldf['Hexanal Variance'],scatter_kws={"s": 175},color='b')
sns.despine()
plt.ylabel('Variance', fontsize=48);
plt.title('Mean vs. Variance', fontsize=55);
plt.xlabel('Mean', fontsize=48);
plt.legend(loc=2, prop={'size': 48});

In [7]:
finaldf['Control Mean']


Out[7]:
0     0.358394
1     0.380809
2     0.122499
3     0.369035
4     0.450840
5     0.470184
6     0.484241
7     0.473569
8     0.393696
9     0.592246
10    0.617040
11    0.623864
12    0.513630
13    0.659852
14    0.647230
Name: Control Mean, dtype: float64

Cell by cell, averaged odors


In [13]:
Ccellmean=Cctrl.mean(axis=1)
Ccellvar=Cctrl.var(axis=1)
Mcellmean=M.mean(axis=1)
Mcellvar=M.var(axis=1)
Hcellmean=H.mean(axis=1)
Hcellvar=H.var(axis=1)

In [14]:
#Concat
Ctemp=[Cctrl['Group'],Ccellmean,Ccellvar]
Mtemp=[M['Group'],Mcellmean,Mcellvar]
Htemp=[H['Group'],Hcellmean,Hcellvar]

CtrlcellDF=pd.concat(Ctemp,axis=1)
CtrlcellDF.columns=('Group','Mean','Variance')
McellDF=pd.concat(Mtemp,axis=1)
McellDF.columns=('Group','Mean','Variance')
HcellDF=pd.concat(Htemp,axis=1)
HcellDF.columns=('Group','Mean','Variance')
finalcell=[CtrlcellDF,McellDF,HcellDF]
finalcelldf=pd.concat(finalcell,axis=0)

In [15]:
sns.regplot('Mean','Variance',CtrlcellDF)


Out[15]:
<matplotlib.axes._subplots.AxesSubplot at 0xc099160>

In [18]:
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(30, 15));
sns.regplot('Mean','Variance',CtrlcellDF,scatter_kws={"s": 80},color='r',label='Control')
sns.regplot('Mean','Variance',McellDF,scatter_kws={"s": 80},color='g',label='Mint')
sns.regplot('Mean','Variance',HcellDF,scatter_kws={"s": 80},color='b',label='Hexanal')
sns.despine()
plt.ylabel('Variance', fontsize=48);
plt.title('Mean vs. Variance', fontsize=55);
plt.xlabel('Mean', fontsize=48);
plt.legend(loc=2, prop={'size': 48});

In [ ]: